﻿using System.Collections.ObjectModel;
using System.Data.Linq;
using System.Linq;

namespace PersonaLibrary.Data
{
    public partial class Organization
    {
        private EntityRef<Organization> parent = default(EntityRef<Organization>);
		
        [System.Data.Linq.Mapping.AssociationAttribute(Name = "Organization_Organization", Storage = "parent", 
			ThisKey = "ParentOrganization", OtherKey = "Id", IsForeignKey = true)]
        public Organization Parent
        {
            get
            {
                return parent.Entity;
            }
            set
            {
				SendPropertyChanging();
				parent.Entity = value;

                if ((value != null))
                    ParentOrganization = value.Id;
                else
                    ParentOrganization = default(int?);

				SendPropertyChanged("Parent");
            }
        }

        public override string ToString()
        {
			if (!string.IsNullOrEmpty(Ownership))
				return string.Concat(Ownership, " \"", Name, '"');

        	return Name;
        }
    }
}
